package com.example.securitydemo.authentication;

import com.example.securitydemo.utils.TokenUtils;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

/**
 * @author Cary
 * @date 2022/3/25
 */
public class JwtSecurityConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
    public static final String AUTHORIZATION_HEADER = "Authorization";
    private final TokenUtils tokenUtils;

    public JwtSecurityConfigurer(TokenUtils tokenUtils) {
        this.tokenUtils = tokenUtils;
    }

    @Override
    public void configure(HttpSecurity http) {
        JwtTokenAuthenticationFilter customFilter = new JwtTokenAuthenticationFilter(tokenUtils);
        http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
    }
}
